/**
 * Copyright (c) 2024-2025 National Fundamental Software of China Co., Ltd.
 *
 * You should have find a copy of NFSChina License. If not, please contact us
 * by email <os_support@nfschina>
 *
**/

/*
    SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org>
    SPDX-FileCopyrightText: 2020 Méven Car <meven.car@kdemail.net>
    SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "componentchoosertexteditor.h"
#include <KService>

componentchoosertexteditor::componentchoosertexteditor(QObject *parent)
    : ComponentChooser(parent,
                       QStringLiteral("text/plain"),
                       QStringLiteral("TextEditor"),
                       QStringLiteral("featherpad.desktop"),
                       i18n("Select default text editor"))
{
}

void componentchoosertexteditor::save()
{
    const QString storageId = m_applications[m_index].toMap()["storageId"].toString();

    const KService::Ptr Service = KService::serviceByStorageId(storageId);
    if (!Service) {
        return;
    }

    saveMimeTypeAssociation(QStringLiteral("text/plain"), storageId);
}
